//
//  WKMainTabController.m
//  TangSengDaoDao
//
//  Created by tt on 2019/12/7.
//  Copyright © 2019 xinbida. All rights reserved.
//

#import "WKMainTabController.h"
#import <WuKongBase/WuKongBase.h>
#import <Lottie/Lottie.h>
#import "WKConversationListVC.h"
#import "WKContactsVC.h"
#import "WKMeVC.h"
@interface WKMainTabController ()<UITabBarControllerDelegate>

@property(nonatomic,strong) LOTAnimationView *currentLOTAnimationView;

@end

@implementation WKMainTabController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.delegate = self;
    // Do any additional setup after loading the view.
    [self.tabBar setBarTintColor:[UIColor whiteColor]];
    
    [[UITabBar appearance] setShadowImage:[[UIImage alloc]init]];
    [[UITabBar appearance] setBackgroundImage:[[UIImage alloc]init]];
    if (@available(iOS 13.0, *)) {
//        [self.tabBar setBarTintColor:[UIColor systemBackgroundColor]];
//        [self.tabBar setBackgroundColor:[UIColor systemBackgroundColor]];
        [self.tabBar setBarTintColor:[UIColor colorWithHexString:@"#f6f6f6"]];
        [self.tabBar setBackgroundColor:[UIColor colorWithHexString:@"#f6f6f6"]];
    } else {
//        [self.tabBar setBarTintColor:[UIColor whiteColor]];
//        [self.tabBar setBackgroundColor:[UIColor whiteColor]];
        [self.tabBar setBarTintColor:[UIColor colorWithHexString:@"#f6f6f6"]];
        [self.tabBar setBackgroundColor:[UIColor colorWithHexString:@"#f6f6f6"]];
    }
    
    UIFont *font = [UIFont systemFontOfSize:10];
    UIColor *selTitleColor = [UIColor colorWithHexString:@"#0064d7"];
    UIColor *norTitleColor = [UIColor colorWithHexString:@"#828282"];
    // 普通状态下的文字属性
    NSDictionary *normalAttrs = @{NSForegroundColorAttributeName:norTitleColor, NSFontAttributeName:font};
    
    // 选中状态下的文字属性
    NSDictionary *selectedAttrs = @{NSForegroundColorAttributeName:selTitleColor, NSFontAttributeName:font};
    
    // 设置文字属性
    UITabBarItem *tabBarItem = [UITabBarItem appearance];
    [tabBarItem setTitleTextAttributes:normalAttrs forState:UIControlStateNormal];
    [tabBarItem setTitleTextAttributes:selectedAttrs forState:UIControlStateHighlighted];
    [tabBarItem setTitleTextAttributes:selectedAttrs forState:UIControlStateSelected];
//    tabBarItem.titlePositionAdjustment = UIOffsetMake(0.0, -3.0);
    
    
    // 通讯录
    [self setupChildVC:WKContactsVC.class title:@"联系人" andImage:@"ic_tab_contact_nor" andSelectImage:@"ic_tab_contact_sel"];
   
    // 聊天列表
    [self setupChildVC:WKConversationListVC.class title:@"聊天" andImage:@"ic_tab_chat_nor" andSelectImage:@"ic_tab_chat_sel"];
    
    // 我的
    [self setupChildVC:WKMeVC.class title:@"我的" andImage:@"ic_tab_mine_nor" andSelectImage:@"ic_tab_mine_sel"];

}

- (void)setupChildVC:(Class)vc title:(NSString *)title andImage:(NSString * )image andSelectImage:(NSString *)selectImage{
    
    UIViewController * vcInstall = [[vc alloc] init];
    //VC.view.backgroundColor = UIColor.whiteColor;
    vcInstall.tabBarItem.title = title;
    vcInstall.tabBarItem.image = [[UIImage imageNamed:image]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    vcInstall.tabBarItem.selectedImage = [[UIImage imageNamed:selectImage]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
//    vcInstall.tabBarItem.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
    [self addChildViewController:vcInstall];
}


-(void) dealloc {
    WKLogDebug(@"WKMainTabController dealloc");
}

#pragma mark - UITabBarControllerDelegate

static UIImpactFeedbackGenerator *impactFeedBack;
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
    
    if(!impactFeedBack) {
        impactFeedBack = [[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleLight];
    }
    [impactFeedBack prepare];
    [impactFeedBack impactOccurred];
}

@end

